package com.fwpj.rule;

import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.ArrayList;

import javax.annotation.Resource;
import javax.ejb.Stateless;
import javax.jms.Connection;
import javax.jms.ConnectionFactory;
import javax.jms.DeliveryMode;
import javax.jms.Destination;
import javax.jms.JMSException;
import javax.jms.MessageProducer;
import javax.jms.Session;
import javax.jms.TextMessage;

import com.common.bo.Node;
import com.common.util.ObjectUtils;
import com.common.util.ObjectXmlUtils;
import com.common.util.impl.ObjectXmlUtilsAttributeImpl;
import com.core.service.AppBaseService;
import com.fwpj.entity.*;
import com.fwpj.rule.SVC_FWPJ_RULELocal;
import com.fwpj.rule.SVC_FWPJ_RULERemote;

@Stateless
public class SVC_FWPJ_RULE extends AppBaseService implements
		SVC_FWPJ_RULERemote, SVC_FWPJ_RULELocal {
	@Resource(name = "JmsConnectionFactory")
	private ConnectionFactory connectionFactory;

	@Override
	public Map rule(Map param) {
		List list = new ArrayList();
		List LIST_TB_FWPJ_SHJBXX_PJSQ_KZSX = ObjectUtils.getMapValue(param,
				"LIST_TB_FWPJ_SHJBXX_PJSQ_KZSX", List.class);
		if (LIST_TB_FWPJ_SHJBXX_PJSQ_KZSX != null) {
			for (Object item : LIST_TB_FWPJ_SHJBXX_PJSQ_KZSX) {
				TB_FWPJ_SHJBXX_PJSQ_KZSX kzsx = ObjectUtils.mapToJavaBean(
						(Map) item, TB_FWPJ_SHJBXX_PJSQ_KZSX.class);
				int k = 0;
				System.out.print("\n\n" + kzsx.getUILX() + "\n\n");
				if (kzsx.getUILX()!= null) {
					if (kzsx.getUILX().equals("RadioButton"))
						k = 1;
					else if (kzsx.getUILX().equals("CheckBox"))
						k = 2;
					else if (kzsx.getUILX().equals("TextInput"))
						k = 3;
				}
				switch (k) {
				case 1:
					list.add(kzsx);
					break;
				case 2:
					list.add(kzsx);
					break;
				case 3:
					Map P = new HashMap();
					P.put("LXDYID", kzsx.getLXDYID());
					List result = getResultList(
							"Q_FWPJ_LXDY.GET_TB_FWPJ_LXDY_KZSXZ_BY_LXDYID", P);
					Iterator iter = result.iterator();
					while (iter.hasNext()) {
						TB_FWPJ_LXDY_KZSXZ node = (TB_FWPJ_LXDY_KZSXZ) iter
								.next();
						String bdscl;
						bdscl = bdscl(kzsx.getSXZ(), node.getSXZ());
						System.out.print("\n\n----bdscl--"+bdscl+"");
						if (!bdscl.equals("null")) {
							kzsx.setSXZ(node.getSXZ());
							kzsx.setFZ((float) node.getFZ());
							list.add(kzsx);
							break;
						}
//						else if(bdscl.equals("null")){
//							kzsx.setSXZ("");
//							kzsx.setFZ((float)0);
//							list.add(kzsx);
//						}
					}

					break;
				}

			}
		}
		Map pram = new HashMap();
		pram.put("LIST_TB_FWPJ_SHJBXX_KZSX", list);
		return pram;
	}
	@Override//表达式处理
	public String bdscl(String sxz, String str) {
		System.out.print("\n\n-----sxz" + sxz + "\n\n=====str" + str);
		int k = Integer.parseInt(sxz);
		String nums[] = str.split("\\D+");
		int xy = str.split("<").length - 1;
		int dy = str.split(">").length - 1;
		if (xy == 2) {
			if (Integer.parseInt(nums[0]) <= k && k < Integer.parseInt(nums[1])) {
				System.out.print("\n\n<k<");
				return str;
			}
		} else if (dy == 2) {
			if (Integer.parseInt(nums[0]) > k && k >= Integer.parseInt(nums[1])) {
				System.out.print("\n\n>k>");
				return str;
			}
		} else if (nums.length == 2 && nums[1] != null) {
			if (xy == 1 && k < Integer.parseInt(nums[1])) {
				System.out.print("\n\nk<");
				return str;
			}
			if (dy == 1 && k >= Integer.parseInt(nums[1])) {
				System.out.print("\n\nk>");
				return str;
			}
		} else if (nums.length == 1 && nums[0] != null) {
			if (xy == 1 && Integer.parseInt(nums[0]) <= k) {
				System.out.print("\n\n<k");
				return str;
			}
			if (dy == 1 && Integer.parseInt(nums[0]) > k) {
				System.out.print("\n\n>k");
				return str;
			}
		}
		return "null";
	}

}